// pages/mine/collection/collection.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    collects: [],
    page: 1,
  },
  //load
  load: function(e) {
    let that = this;
    let page = this.data.page;
    page = page + 1;
    that.setData({
      page: page
    })
    this.list();
    console.log("update")
  },
  //收藏
  get_collects(_page) {
    let that = this;
    wx.request({
      url: app.globalData.url + 'api/mine/collects',
      method: 'POST',
      data: {
        token: app.globalData.token,
        page: _page,
        op: '12',
      },
      success: function(e) {
        console.log(e)
        // console.log(e.data.data.collects);
        if (e.data.data.current_page > e.data.data.total_page) {
          console.log("到底了");
          wx.showToast({
            title: '到底啦~',
            icon: 'none',
          })
        } else {
          if (that.data.collects == "") {
            that.setData({
              collects: e.data.data.collects,
            })
          } else {
            // console.log("不不不不不");
            let collects = that.data.collects;
            let _collects = e.data.data.collects;
            collects.push(..._collects)
            console.log(collects);
            that.setData({
              collects: collects,
            })
          }
        }
        wx.hideLoading();
      }
    })
  },
  // 加载
  list: function(e) {
    let that = this;
    let page = this.data.page
    that.get_collects(page);
    wx.showLoading({
      icon: 'none',
    })

  },

  //详情
  go_detail: function(e) {
    // console.log(e.currentTarget.dataset.deatil_id)
    let deatil_id = e.currentTarget.dataset.deatil_id,
      status = e.currentTarget.dataset.status;
    if (status == 1) {
      wx.navigateTo({
        url: '../../recruit/detail/detail?deatil_id=' + deatil_id,
      })
    } else {
      wx.showToast({
        title: '该职位已失效',
        icon: 'none'
      })
    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    let that = this;
    this.list();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {
    this.setData({
      collects: [],
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {
    this.setData({
      collects: [],
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})